package bingo.rpc.framework.cluster.impl;

import bingo.rpc.framework.cluster.ClusterStrategy;
import bingo.rpc.framework.model.ProviderService;
import org.apache.commons.lang3.RandomUtils;

import java.util.List;

/**
 * 随机软负载均衡算法实现
 * @author hujinsheng
 * @project bingo
 * @create 2017-12-14 13:49
 **/
public class RandomClusterStrategyImpl implements ClusterStrategy {
    @Override
    public ProviderService select(List<ProviderService> providerServices) {
        int MAX_LEN=providerServices.size();
        int index= RandomUtils.nextInt(0,MAX_LEN-1);

        return providerServices.get(index);
    }
}
